<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>版本管理 - 智慧题库系统</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <style>
        .chapter-tree ul {
            margin-left: 1.5rem;
            border-left: 2px dashed #e5e7eb;
            padding-left: 1rem;
        }
        .chapter-tree li {
            margin-bottom: 0.5rem;
            position: relative;
        }
        .chapter-tree li::before {
            content: '';
            position: absolute;
            left: -1.2rem;
            top: 0.7rem;
            width: 0.5rem;
            height: 0.5rem;
            background: #165DFF;
            border-radius: 50%;
            display: inline-block;
        }
    </style>
</head>
<body class="bg-gray-50 font-inter text-gray-800 min-h-screen flex flex-col">
    <!-- 顶部导航栏 -->
    <header class="bg-white shadow-sm sticky top-0 z-50">
        <div class="container mx-auto px-4 py-3 flex items-center justify-between">
            <div class="flex items-center space-x-2">
                <i class="fa fa-graduation-cap text-primary text-2xl"></i>
                <h1 class="text-xl font-bold text-gray-800">智慧题库系统</h1>
            </div>
            <div class="hidden md:flex items-center space-x-6">
                <a href="#" class="text-primary font-medium border-b-2 border-primary pb-1">首页</a>
                <a href="#" class="text-gray-600 hover:text-primary transition-colors">题库</a>
                <a href="#" class="text-gray-600 hover:text-primary transition-colors">教材版本</a>
                <a href="#" class="text-gray-600 hover:text-primary transition-colors">统计分析</a>
                <a href="#" class="text-gray-600 hover:text-primary transition-colors">系统设置</a>
            </div>
            <div class="flex items-center space-x-4">
                <button class="text-gray-500 hover:text-primary transition-colors">
                    <i class="fa fa-bell-o"></i>
                </button>
                <div class="flex items-center space-x-2">
                    <img src="https://picsum.photos/id/1001/40/40" alt="用户头像" class="w-8 h-8 rounded-full">
                    <span class="text-sm font-medium">李老师</span>
                </div>
            </div>
        </div>
    </header>

    <div class="flex flex-1">
        <!-- 左侧版本列表 -->
        <aside class="w-72 bg-white border-r min-h-screen">
            <div class="p-4 border-b">
                <input id="searchInput" type="text" placeholder="搜索版本..." class="w-full px-3 py-2 border border-gray-300 rounded focus:ring-2 focus:ring-primary/20 mb-2" />
                <button id="addVersionBtn" class="w-full px-4 py-2 bg-primary text-white rounded hover:bg-primary/90 transition-colors"><i class="fa fa-plus mr-1"></i>新增版本</button>
            </div>
            <ul id="versionList" class="version-list divide-y divide-gray-100">
                <!-- 动态渲染版本列表 -->
            </ul>
        </aside>

        <!-- 右侧详情区 -->
        <main class="flex-1 p-8">
            <div class="flex justify-between items-center mb-4">
                <h2 class="text-2xl font-bold">版本管理</h2>
                <div>
                    <button id="syncBtn" class="btn px-4 py-2 bg-blue-100 text-primary rounded hover:bg-blue-200 mr-2"><i class="fa fa-refresh mr-1"></i>同步</button>
                    <button id="compareBtn" class="btn px-4 py-2 bg-green-100 text-green-700 rounded hover:bg-green-200 mr-2"><i class="fa fa-exchange mr-1"></i>对比</button>
                    <button id="deleteBtn" class="btn px-4 py-2 bg-red-100 text-red-700 rounded hover:bg-red-200"><i class="fa fa-trash mr-1"></i>删除</button>
                </div>
            </div>
            <div id="versionInfo" class="bg-white rounded shadow p-4 mb-6">
                <!-- 动态渲染版本信息 -->
            </div>
            <div class="bg-white rounded shadow p-4">
                <h3 class="font-bold mb-2">章节结构</h3>
                <div id="chapterTree" class="chapter-tree">
                    <!-- 动态渲染章节树 -->
                </div>
            </div>
        </main>
    </div>

    <!-- 新增版本弹窗 -->
    <div id="modal" class="fixed inset-0 bg-black bg-opacity-30 flex items-center justify-center z-50 hidden">
        <div class="bg-white rounded-lg w-full max-w-md mx-4 p-6">
            <h3 class="text-lg font-semibold mb-4">新增教材版本</h3>
            <form id="addForm">
                <div class="mb-3">
                    <label class="block text-sm font-medium mb-1">名称</label>
                    <input name="name" type="text" class="w-full px-3 py-2 border border-gray-300 rounded" required />
                </div>
                <div class="mb-3">
                    <label class="block text-sm font-medium mb-1">出版社</label>
                    <input name="publisher" type="text" class="w-full px-3 py-2 border border-gray-300 rounded" required />
                </div>
                <div class="mb-3 grid grid-cols-2 gap-2">
                    <div>
                        <label class="block text-sm font-medium mb-1">学段</label>
                        <input name="stage" type="text" class="w-full px-3 py-2 border border-gray-300 rounded" required />
                    </div>
                    <div>
                        <label class="block text-sm font-medium mb-1">年级</label>
                        <input name="grade" type="text" class="w-full px-3 py-2 border border-gray-300 rounded" required />
                    </div>
                </div>
                <div class="mb-3">
                    <label class="block text-sm font-medium mb-1">出版年份</label>
                    <input name="year" type="number" class="w-full px-3 py-2 border border-gray-300 rounded" required />
                </div>
                <div class="mb-3">
                    <label class="block text-sm font-medium mb-1">状态</label>
                    <select name="status" class="w-full px-3 py-2 border border-gray-300 rounded">
                        <option value="现行">现行</option>
                        <option value="过渡">过渡</option>
                        <option value="停用">停用</option>
                    </select>
                </div>
                <div class="flex justify-end gap-2 mt-4">
                    <button type="button" id="closeModal" class="px-4 py-2 bg-gray-100 rounded hover:bg-gray-200">取消</button>
                    <button type="submit" class="px-4 py-2 bg-primary text-white rounded hover:bg-primary/90">保存</button>
                </div>
            </form>
        </div>
    </div>

    <script>
        // 模拟数据
        let versions = [
            {
                id: 1,
                name: '人教版 2023',
                publisher: '人民教育出版社',
                stage: '高中',
                grade: '高一',
                year: 2023,
                status: '现行',
                chapters: [
                    { name: '第一章 集合与常用逻辑用语', children: [
                        { name: '1.1 集合的含义与表示' },
                        { name: '1.2 集合的基本运算' }
                    ]},
                    { name: '第二章 函数与基本初等函数', children: [
                        { name: '2.1 函数的概念' },
                        { name: '2.2 指数函数与对数函数' }
                    ]}
                ]
            },
            {
                id: 2,
                name: '苏教版 2022',
                publisher: '江苏教育出版社',
                stage: '高中',
                grade: '高一',
                year: 2022,
                status: '现行',
                chapters: [
                    { name: '第一章 集合', children: [
                        { name: '1.1 集合的含义' },
                        { name: '1.2 集合的表示方法' }
                    ]},
                    { name: '第二章 函数', children: [
                        { name: '2.1 函数的定义' },
                        { name: '2.2 函数的性质' }
                    ]}
                ]
            }
        ];
        let selectedId = versions[0].id;

        function renderVersionList() {
            const list = document.getElementById('versionList');
            const search = document.getElementById('searchInput').value.trim();
            list.innerHTML = '';
            versions.filter(v => !search || v.name.includes(search)).forEach(v => {
                const li = document.createElement('li');
                li.className = 'px-4 py-3 cursor-pointer hover:bg-primary/5' + (v.id === selectedId ? ' bg-primary/10 font-bold text-primary' : '');
                li.textContent = v.name;
                li.onclick = () => { selectedId = v.id; renderAll(); };
                list.appendChild(li);
            });
        }

        function renderVersionInfo() {
            const info = document.getElementById('versionInfo');
            const v = versions.find(v => v.id === selectedId);
            if (!v) { info.innerHTML = '<div class="text-gray-400">请选择一个版本</div>'; return; }
            info.innerHTML = `
                <div class="grid grid-cols-2 gap-4">
                    <div><strong>名称：</strong>${v.name}</div>
                    <div><strong>出版社：</strong>${v.publisher}</div>
                    <div><strong>学段：</strong>${v.stage}</div>
                    <div><strong>年级：</strong>${v.grade}</div>
                    <div><strong>出版年份：</strong>${v.year}</div>
                    <div><strong>状态：</strong>${v.status}</div>
                </div>
            `;
        }

        function renderChapterTree() {
            const tree = document.getElementById('chapterTree');
            const v = versions.find(v => v.id === selectedId);
            if (!v) { tree.innerHTML = '<div class="text-gray-400">无章节数据</div>'; return; }
            function renderNodes(nodes) {
                if (!nodes) return '';
                return `<ul>${nodes.map(n => `<li>${n.name}${n.children ? renderNodes(n.children) : ''}</li>`).join('')}</ul>`;
            }
            tree.innerHTML = renderNodes(v.chapters);
        }

        function renderAll() {
            renderVersionList();
            renderVersionInfo();
            renderChapterTree();
        }

        // 搜索功能
        document.getElementById('searchInput').oninput = renderVersionList;

        // 新增版本弹窗
        document.getElementById('addVersionBtn').onclick = () => {
            document.getElementById('modal').classList.remove('hidden');
        };
        document.getElementById('closeModal').onclick = () => {
            document.getElementById('modal').classList.add('hidden');
        };
        document.getElementById('addForm').onsubmit = function(e) {
            e.preventDefault();
            const form = e.target;
            const newVersion = {
                id: Date.now(),
                name: form.name.value,
                publisher: form.publisher.value,
                stage: form.stage.value,
                grade: form.grade.value,
                year: form.year.value,
                status: form.status.value,
                chapters: []
            };
            versions.push(newVersion);
            selectedId = newVersion.id;
            renderAll();
            document.getElementById('modal').classList.add('hidden');
            form.reset();
        };

        // 删除版本
        document.getElementById('deleteBtn').onclick = function() {
            if (confirm('确定要删除该版本吗？')) {
                versions = versions.filter(v => v.id !== selectedId);
                selectedId = versions.length ? versions[0].id : null;
                renderAll();
            }
        };

        // 同步、对比功能（仅演示）
        document.getElementById('syncBtn').onclick = function() {
            alert('同步成功！（演示）');
        };
        document.getElementById('compareBtn').onclick = function() {
            alert('请选择两个版本进行对比！（演示）');
        };

        // 初始化
        renderAll();
    </script>
</body>
</html>
